package c.f.c.a;

import android.os.Looper;
import c.f.c.a.j.f;
import c.f.c.a.j.g;
import c.f.c.a.j.h;
import c.f.c.a.j.h.a;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;

public class i {
    public static h a = new h();

    public static <TResult> TResult a(f<TResult> fVar) throws ExecutionException, InterruptedException {
        String str = "await must not be called on the UI thread";
        if (Looper.myLooper() != Looper.getMainLooper()) {
            boolean z;
            f fVar2 = (f) fVar;
            synchronized (fVar2.a) {
                z = fVar2.b;
            }
            if (z) {
                return h.a(fVar);
            }
            a aVar = new a();
            fVar.c(aVar);
            fVar.a(aVar);
            aVar.a.await();
            return h.a(fVar);
        }
        throw new IllegalStateException(str);
    }

    public static <TResult> f<TResult> b(Callable<TResult> callable) {
        h hVar = a;
        ExecutorService executorService = h.d.b;
        g gVar = new g();
        try {
            executorService.execute(new g(hVar, gVar, callable));
        } catch (Exception e) {
            gVar.a(e);
        }
        return gVar.a;
    }
}
